package com.micrograils

import com.micrograils.domain.Author
import com.micrograils.domain.Book
import grails.gorm.transactions.Transactional
import org.grails.orm.hibernate.HibernateDatastore

class GormApplication {

    static void main(String[] args) {

        // config HibernateDatastore.
        Map configuration = [
                'hibernate.hbm2ddl.auto': 'create-drop',
                'dataSource.url'        : 'jdbc:h2:mem:myDB'
        ]
        HibernateDatastore datastore = new HibernateDatastore(configuration, Author, Book)

        new GormApplication().demoService()
    }

    @Transactional
    def demoService() {
        new Author(name: 'Aaron', age: 18).save()
        println Author.count()
        println Author.findAllByAgeGreaterThan(10)

        new Book(name: 'Micro-Grails', ISBN: '9787512432031')
        println Book.count()
    }

}
